package fr.isima.myant;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class CopyTask extends Task {
	private String from;
	private String to;
	
	public CopyTask(){}
	
	public void setFrom(String from) {
		this.from = from;
	}
	
	public void setTo(String to) {
		this.to = to;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("\t\tName : CopyTask");
		sb.append("\t\tFrom " + from);
		sb.append("\t\tTo " + to);
		sb.append("\n");
		
		return sb.toString();
	}
	
	@Override
	public void execute() {
		try {
			Files.copy(Paths.get(from), Paths.get(to), StandardCopyOption.REPLACE_EXISTING);
		} catch (IOException e) {
			System.err.println("Fichier inconnu lors de la copie");
		}
	}
}